import matplotlib.pyplot as plt
import matplotlib.dates as mdate
import seaborn as sns
import matplotlib as mpl

mpl.rcParams['font.family']='serif' # pd.plot中文
# 显示中文
plt.rcParams['font.sans-serif'] = ['SimHei']
# 用来正常显示负号
mpl.rcParams['axes.unicode_minus'] = False
# 图表主题
plt.style.use('seaborn')

fsize = (14, 9)
# 双Y坐标轴画图
# df 只有包含3列：index,左坐标列，右坐标列
# date_format like '%Y-%m-%d'
def plotyyCrowdingRate(df, date_format: str, title: str, l_tittle, r_tittle):
    fig = plt.figure(figsize=(fsize[0] ,fsize[1]))

    ax1 = fig.add_subplot(111)
    ax1.xaxis.set_major_formatter(mdate.DateFormatter(date_format))  # 设置时间标签显示格式
    ax1.plot(df['index'], df['left'] ,)
    ax1.set_ylabel(l_tittle ,fontdict={'weight': 'normal', 'size': 15})
    ax1.set_title(title ,fontdict={'weight': 'normal', 'size': 15})

    ax2 = ax1.twinx()  # this is the important function
    ax2.plot(df['index'], df['right'], 'r') # 拥挤率用红色标记
    ax2.set_ylabel(r_tittle ,fontdict={'weight': 'normal', 'size': 15})
    ax2.set_xlabel('Same')